﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppData;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace BFOAuction.DAL.Register
{
    public class DAL_Register
    {

        public AppFormat.MyError Insert_Account(DTO.Register.Register objAccount)
        {
            AppFormat.MyError Error = new AppFormat.MyError();
            ConnectData objCon = new ConnectData();
            try
            {
                objCon.StrConnect = DataProvider.Connection();
                objCon.CreateConnect();
                SqlParameter[] p = new SqlParameter[2];
                p[0] = new SqlParameter("@" + DTO.Register.Register.colTenDangNhap, objAccount.StrTenDangNhap);
                p[1] = new SqlParameter("@" + DTO.Register.Register.colMatKhau, objAccount.StrMatKhau);

                objCon.execProc("Add_Account", p);

            }
            catch (Exception ex)
            {
                objCon.ClosedConnect();
                Error.IsError = true;
                Error.TypeError = AppFormat.MyError.enTypeError.Select;
                Error.MessageErrorDetail = objCon.ReturnMyError.MessageErrorDetail;
                Error.MessageError = "Lỗi thêm thông tin account xin vui lòng kiểm tra lại !!! ( " + ex.Message + " )";
            }
            finally
            {
                objCon.ClosedConnect();
            }
            return Error;
        }

        #region Insert_Customer

        public AppFormat.MyError Insert_Info_Customer(DTO.Register.Register objRegisterType)
        {
            AppFormat.MyError Error = new AppFormat.MyError();
            ConnectData objCon = new ConnectData();
            try
            {
                objCon.StrConnect = DataProvider.Connection();
                objCon.CreateConnect();
                SqlParameter[] p = new SqlParameter[7];
                p[0] = new SqlParameter("@" + DTO.Register.Register.colHoTen, objRegisterType.StrHoTen);
                p[1] = new SqlParameter("@" + DTO.Register.Register.colGioiTinh, objRegisterType.StrGioiTinh);
                p[2] = new SqlParameter("@" + DTO.Register.Register.colCMND, objRegisterType.LCMND);
                p[3] = new SqlParameter("@" + DTO.Register.Register.colDiaChi, objRegisterType.StrDiaChi);
                p[4] = new SqlParameter("@" + DTO.Register.Register.colThanhPho, objRegisterType.StrThanhPho);
                p[5] = new SqlParameter("@" + DTO.Register.Register.colDienThoai, objRegisterType.LDienThoai);
                p[6] = new SqlParameter("@" + DTO.Register.Register.colEmail, objRegisterType.StrEmail);

                objCon.execProc("Add_Info_Customer", p);

            }
            catch (Exception ex)
            {
                objCon.ClosedConnect();
                Error.IsError = true;
                Error.TypeError = AppFormat.MyError.enTypeError.Select;
                Error.MessageErrorDetail = objCon.ReturnMyError.MessageErrorDetail;
                Error.MessageError = "Lỗi thêm thông tin khách hàng !!! ( " + ex.Message + " )";
            }
            finally
            {
                objCon.ClosedConnect();
            }
            return Error;
        }

        #endregion

        #region Insert_Payment

        public AppFormat.MyError Insert_Info_Payment(DTO.Register.Register objPaymentType)
        {
            AppFormat.MyError Error = new AppFormat.MyError();
            ConnectData objCon = new ConnectData();
            try
            {
                objCon.StrConnect = DataProvider.Connection();
                objCon.CreateConnect();
                SqlParameter[] p = new SqlParameter[2];
                p[0] = new SqlParameter("@" + DTO.Register.Register.colMaSoTaiKhoan, objPaymentType.LMaSoTaiKhoan);
                p[1] = new SqlParameter("@" + DTO.Register.Register.colMatKhau, objPaymentType.LSoDu);

                objCon.execProc("Add_Info_Payment", p);

            }
            catch (Exception ex)
            {
                objCon.ClosedConnect();
                Error.IsError = true;
                Error.TypeError = AppFormat.MyError.enTypeError.Select;
                Error.MessageErrorDetail = objCon.ReturnMyError.MessageErrorDetail;
                Error.MessageError = "Lỗi thêm thông tin tài khoản thanh toán !!! ( " + ex.Message + " )";
            }
            finally
            {
                objCon.ClosedConnect();
            }
            return Error;
        }

        #endregion

    }
}
